﻿namespace Groundwork.Extensions
{
    using System;

    /// <summary>
    /// Numeric Extensions
    /// </summary>
    public static class Numerics
    {
        /// <summary>
        /// Checks if the input value is greater than the max value.
        /// </summary>
        /// <typeparam name="T">IComparable type to test</typeparam>
        /// <param name="value">current value to be test</param>
        /// <param name="maxValue">value boundary</param>
        /// <returns>true or false indicating if the boundary was exceeded</returns>
        public static bool IsGreaterOrEqual<T>(this T value, T maxValue) where T : IComparable
        {
            if (value.IsNumber())
            {
                return value.CompareTo(maxValue) >= 0;
            }
            
            return false;
        }

        /// <summary>
        /// Checks if the input value is less than the max value.
        /// </summary>
        /// <typeparam name="T">IComparable type to test</typeparam>
        /// <param name="value">current value to be test</param>
        /// <param name="minValue">value boundary</param>
        /// <returns>true or false indicating if the boundary was exceeded</returns>
        public static bool IsLessOrEqual<T>(this T value, T minValue) where T : IComparable
        {
            if (value.IsNumber())
            {
                return value.CompareTo(minValue) <= 0;
            }

            return false;
        }

        /// <summary>
        /// Checks if the input value is within the value range minValue to maxValue
        /// </summary>
        /// <typeparam name="T">IComparable type to test</typeparam>
        /// <param name="value">current value to be test</param>
        /// <param name="minValue">lower value boundary</param>
        /// <param name="maxValue">upper value boundary</param>
        /// <returns>true or false indicating if the boundary range was exceeded</returns>
        public static bool IsBetween<T>(this T value, T minValue, T maxValue) where T : IComparable
        {
            if (value.CompareTo(minValue) >= 0 && value.CompareTo(maxValue) <= 0)
            {
                return true;
            }

            return false;
        }
        
    }
}
